/*****************************************************************************
* File Name: motion_sensor.h
*
* Version: 1.0
*
* Description:
* This file contains API for motion sensor
*
* Note:
* Define DISABLE_MOTION_SENSOR in platform.h to disable motion sensor module
*
* Owner: KMVP
*
* Related Document:
* SCB component datasheet
*
* Hardware Dependency:
* MPU6500 Datasheet
*
* Code Tested With:
* 1. PSoC Creator 3.1 
* 2. ARM GCC 4.8.4
******************************************************************************
* Copyright (2015), Cypress Semiconductor Corporation.
******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
*****************************************************************************/
#ifndef _MOTION_SENSOR_HAL_H_
#define _MOTION_SENSOR_HAL_H_

#ifndef DISABLE_MOTION_SENSOR

#include "motion_sensor.h"
#include "mpu6500.h"

/* Function prototype for the application to register */
typedef void(*MotionSensorCBK)(void);

#define Motion_Sensor_Hal_Start()                       Motion_Sensor_I2C_Wakeup();MPU6500_Start()
#define Motion_Sensor_Hal_Stop()                        MPU6500_Stop();Motion_Sensor_I2C_Sleep()

#ifndef DISABLE_MOTION_SENSOR_PINREAD
#define Motion_Sensor_Hal_IsMotionDetected()            Motion_Sensor_Interrupt_Pin_Read()
#else
#define Motion_Sensor_Hal_IsMotionDetected()            ((MPU6500_ReadRegister(MPU6500_INT_STATUS_ADR) & BIT_6_MASK)>>BIT_6_POSITION)
#endif /* DISABLE_MOTION_SENSOR_PINREAD */
/*****************************************************************************
* Function Name: Motion_Sensor_Hal_Init()
******************************************************************************
* Summary:
* This function is used to initlize the motion sensor by calling the reseting 
* Nthe motion sensor and calling motion sensor driver
* and reseting the device.
*
* Parameters:
* MotionSensorCBK cbk - callback function that need to be registered 
*
* Return:
* None
*****************************************************************************/
void Motion_Sensor_Hal_Init(MotionSensorCBK cbk);

/*****************************************************************************
* Function Name: Motion_Sensor_Hal_GetGyroData()
******************************************************************************
* Summary:
* This function is used to collect the gyroscope data
*
* Parameters:
* int16 *buffer - buffer pointer where the gyroscope data is filled
*
* Return:
* None
*****************************************************************************/
void Motion_Sensor_Hal_GetGyroData(int16 *buffer);

/*****************************************************************************
* Function Name: Motion_Sensor_Hal_GetAccData()
******************************************************************************
* Summary:
* This function is used to collect the accelerometer data and manimpulate the
* data to follow the data processing  conventions.
*
* Parameters:
* int16 *buffer - buffer pointer where the gyro data is filled
*
* Return:
* None
*****************************************************************************/
void Motion_Sensor_Hal_GetAccData(int16 *buffer);

/*****************************************************************************
* Function Name: Motion_Sensor_Hal_Enable_LowPowerMode()
******************************************************************************
* Summary:
* This function is used to put motion sensor in low power mode by disabling gyroscope
* and enabling accelerometer in motion detect mode
*
* Parameters:
* None
*
* Return:
* None
*****************************************************************************/
void Motion_Sensor_Hal_Enable_LowPowerMode(void);

/*****************************************************************************
* Function Name: Motion_Sensor_Hal_Disable_LowPowerMode()
******************************************************************************
* Summary:
* This function is stop motion detect low power mode of motion sensor and restore
* default configuration of motion sensor
*
* Parameters:
* None
*
* Return:
* None
*****************************************************************************/
void Motion_Sensor_Hal_Disable_LowPowerMode(void);

#else
#define Motion_Sensor_Hal_Init(cbk)
#define Motion_Sensor_Hal_GetGyroData(buffer)
#define Motion_Sensor_Hal_GetAccData(buffer)
#define Motion_Sensor_Hal_Enable_LowPowerMode()
#define Motion_Sensor_Hal_Disable_LowPowerMode()
#define Motion_Sensor_Hal_Start()                       
#define Motion_Sensor_Hal_Stop()                        
#define Motion_Sensor_Hal_IsMotionDetected()
#endif /* DISABLE_MOTION_SENSOR */
#endif /* _MOTION_SENSOR_HAL_H_ */
